{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import re\n",
    "import regex\n",
    "regex.DEFAULT_VERSION = regex.V0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def time_regex(pattern, value):\n",
    "    %time regex.compile(pattern).match(value)\n",
    "    %time re.compile(pattern).match(value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 0 ns, sys: 0 ns, total: 0 ns\n",
      "Wall time: 362 µs\n",
      "CPU times: user 23.9 s, sys: 0 ns, total: 23.9 s\n",
      "Wall time: 24 s\n"
     ]
    }
   ],
   "source": [
    "time_regex(r\"(\\S+)+x\", 'a' * 28)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 0 ns, sys: 0 ns, total: 0 ns\n",
      "Wall time: 356 µs\n",
      "CPU times: user 16.1 s, sys: 4 ms, total: 16.1 s\n",
      "Wall time: 16.1 s\n"
     ]
    }
   ],
   "source": [
    "time_regex(r\"(x+x+)+y\", 'x' * 28)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 13.1 s, sys: 4 ms, total: 13.1 s\n",
      "Wall time: 13.1 s\n",
      "CPU times: user 22.8 s, sys: 0 ns, total: 22.8 s\n",
      "Wall time: 22.9 s\n"
     ]
    }
   ],
   "source": [
    "n = 28\n",
    "time_regex(('a?' * n) + ('a' * n), 'a' * n)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
